<?php

$array = [
  ['id' => 1, 'date' => "12.01.2020", 'name' => "test1" ],
  ['id' => 2, 'date' => "02.05.2020", 'name' => "test2" ],
  ['id' => 4, 'date' => "08.03.2020", 'name' => "test4" ],
  ['id' => 1, 'date' => "22.01.2020", 'name' => "test1" ],
  ['id' => 2, 'date' => "11.11.2020", 'name' => "test4" ],
  ['id' => 3, 'date' => "06.06.2020", 'name' => "test3"],
];

//1.  make uniq ids
$uniqArray = array_reduce($array, function($accumulator, $item) {
    if (!isset($accumulator[$item['id']])) {
        $accumulator[$item['id']] = $item;
    }
    return $accumulator;
}, []);

//2. sorting
usort($uniqArray, function ($a, $b) {
    return $a['id'] <=> $b['id'];
});

//3. filtering
$filteredArray = array_filter($array , function ($item) {
    return $item['id']  === 1;
});

//4. change keys
$keyValueArray = array_column($array, 'id', 'name');


//5. get goods names and goods ids
$sql = 'SELECT goods.id, goods.name FROM goods
        JOIN goods_tags ON goods.id = goods_tags.goods_id
        GROUP BY goods.id
        HAVING COUNT(DISTINCT goods_tags.tag_id) = (SELECT COUNT(*) FROM tags);';

//6. get departments_ids where gender = man and evaluation > 5
$sql = 'SELECT department_id
        FROM evaluations
        GROUP BY department_id
        HAVING MIN(gender) = TRUE AND MIN(value) > 5;';